var app = angular.module('updateTmApp',[]);
app.controller('updateTmController',function($scope,$http){

    /*获取教师资料*/
    $scope.getTmDetail = function () {

        $scope.tid = $('#getTid').val();
        $scope.tmdata = {tid:$scope.tid};
        $http({
            method: 'POST',
            url: 'teacher/getTmDetail.do',
            params: $scope.tmdata,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function successCallback(response) {
            console.log(response);
            $scope.teacher = response.data.teachermsg;
            $scope.tid = $scope.teacher.tid;
            $scope.tname = $scope.teacher.tname;
            $scope.professinalTitle = $scope.teacher.professinalTitle;
            $scope.contactWay = $scope.teacher.contactWay;
            $scope.instruction = $scope.teacher.instruction;
            $scope.tRole = $scope.teacher.role;
            $scope.status = $scope.teacher.status;
        }, function errorCallback(response) {
            console.log("获取失败！");
        });
    };

    $scope.getTmDetail();

    $scope.backToTmList = function () {
        window.location.href = "/teachermsgUrl.do";
    };

    /*更新教师资料*/
    $scope.updateTmDetail = function () {

        $scope.tRole = $('#tm-role').val();
        $scope.status = $('#tm-status').val();
        $scope.updatedata = {tid:$scope.tid,
            tname:$scope.tname,
            professinalTitle:$scope.professinalTitle,
            contactWay:$scope.contactWay,
            instruction:$scope.instruction,
            role:$scope.tRole,
            status:$scope.status};
        $http({
            method: 'POST',
            url: 'teacher/updateTmDetail.do',
            params: $scope.updatedata,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function successCallback(response) {
            console.log(response);
            $scope.isSuccess = response.data.isSuccess;
            if($scope.isSuccess==0){
                alert("更新成功");
                window.location.href = "/teachermsgUrl.do";
            }else if($scope.isSuccess==1){
                alert("更新出错，请检查内容填写内容是否为空，格式是否正确");
            }
        }, function errorCallback(response) {
            console.log("更新教师详细信息失败！");
        });
    };

    /*更新教师资料*/
    $scope.resetPassword = function () {
        if(confirm("确定重置该用户的密码吗？")){
            $scope.resetData = {tid:$scope.tid};
            $http({
                method: 'POST',
                url: 'teacher/resetPassword.do',
                params: $scope.resetData,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
            }).then(function successCallback(response) {
                console.log(response);
                $scope.isSuccess = response.data.isSuccess;
                if($scope.isSuccess){
                    alert("重置密码成功");
                    window.location.href = "/teachermsgUrl.do";
                }else{
                    alert("重置密码失败");
                }
            }, function errorCallback(response) {
                console.log("重置密码失败！");
            });
        }
    };

});